<?php
/**
 * 描述：资讯-详细。
 * @final
 */
final class Exec_News_Info extends Exec_News_Public
{
    public function Get()
    {
        parent::Get();

        #获取参数
        $id=Functions::UrlArgs('id');
        if(!is_numeric($id))
        {
            header("HTTP/1.0 404 Not Found");
            return;
        }

        #显示逻辑
        if(View::isCached('news/info.tpl',$id))
        {
             View::Display('news/info.tpl',$id);
        }
        else
        {
            #获取数据
            $data=DB::GetRowByID('news',$id);
            if(!$data)
            {
                 header("HTTP/1.0 404 Not Found");
                 return;
            }

            #更新访问次数
            DB::UpdateRowByID('news','ID:'.$id,array(
                'M_Count'=>$data['M_Count']+1
            ));

            #定义标量
            $id_related=array();    //用于记录相关联的记录

            #处理数据
            //类别名
            $data['ClassName']=DAO_NewsClass::GetNameByID($data['ClassID']);
            $data['SubclassName']=DAO_NewsClass::GetNameByID($data['SubclassID']);
            if($data['Thumbnail']){
                $data['Thumbnail']=Config::PATH_RELATIVE_ATTACHMENT_NEWS.'/'.$data['Thumbnail'];
            }
            //下一篇新闻
            $data['IsHaveNext']='FALSE';
            $data['Next_ID']=NULL;
            $data['Next_Title']=NULL;
            $data['Next_M_HTMLFile']=NULL;
			if($data['ClassID'])
            {				
                $data_next=db::GetRows('select * from news where ClassID='.$data['ClassID'].' and ID<'.$data['ID'].' and M_IsDelete=FALSE order by ID desc limit 0,1');

                if($data_next!=NULL)
                {
                    $data['IsHaveNext']='TRUE';
                    $data['Next_ID']=$data_next[0]['ID'];
                    $data['Next_Title']=$data_next[0]['Title'];
                    $data['Next_M_HTMLFile']=Config::PATH_RELATIVE_CONTENT_NEWS.'/detail/'.$data_next[0]['M_HTMLFile'];
                    $id_related[]=$data_next[0]['ID'];
                }
            }
            //上一篇新闻
            $data['IsHavePrevious']='FALSE';
            $data['Previous_ID']=NULL;
            $data['Previous_Title']=NULL;
            $data['Previous_M_HTMLFile']=NULL;
			if($data['ClassID'])
            {
                $data_previous=db::GetRows('select * from news where ClassID='.$data['ClassID'].' and ID>'.$data['ID'].' and M_IsDelete=FALSE order by ID asc limit 0,1');

                if($data_previous!=NULL)
                {
                    $data['IsHavePrevious']='TRUE';
                    $data['Previous_ID']=$data_previous[0]['ID'];
                    $data['Previous_Title']=$data_previous[0]['Title'];
                    $data['Previous_M_HTMLFile']=Config::PATH_RELATIVE_CONTENT_NEWS.'/detail/'.$data_previous[0]['M_HTMLFile'];
                    $id_related[]=$data_previous[0]['ID'];
                }
            }
            
            //相关新闻
            $data_related_keywords=DB::PGetRows("select * from news where ID<>? and concat('；',Keywords,'；') regexp concat('；(',replace(?,'；','|'),')；') and M_IsDelete=FALSE order by Datetime desc limit 0,5",array
            (
                $data['ID'],
                Filter::Mysql_Contact($data['Keywords'])
            ));
            if($data_related_keywords)
            {
                foreach($data_related_keywords as &$row)
                {
                    $row['M_HTMLFile']=Config::PATH_RELATIVE_CONTENT_NEWS.'/detail/'.$row['M_HTMLFile'];
                    $id_related[]=$row['ID'];
                }
                $id_related=array_unique($id_related);  //去掉重复的ID
            }
            View::Assign('News',$data);
            View::Assign('News_Keywords',explode('；',$data['Keywords']));
            View::Assign('News_Related',$data_related_keywords);

            //相关新闻-关联订单
            $data_related_ordersheet=DB::GetRows('select * from news_link where NewsID='.$id.' order by ID desc');
            View::Assign('News_Related_Hand',$data_related_ordersheet);

            #获取数据-数据
            $data=DB::GetRows('select * from news where ClassID='.DAO_NewsClass::DATA_ID.' and M_IsDelete=FALSE order by Datetime desc limit 0,8');
            View::Assign('News_Data',$data);

            #获取数据-法规
            $data=DB::GetRows('select * from news where ClassID='.DAO_NewsClass::LAW_ID.' and M_IsDelete=FALSE order by Datetime desc limit 0,8');
            View::Assign('News_Law',$data);

            #其它数据
            View::Assign('NewsClass_Type_ID',DAO_NewsClass::TYPE_ID);       //核心提示判断选项-船型
            View::Assign('NewsClass_Stardand_ID',DAO_NewsClass::STANDARD_ID);   //核心提示判断选项-船配标准

            #显示页面
            View::Display('news/info.tpl',$id);
        }
    }
}
?>